package com.rbac.web.model.req;

import com.rbac.web.model.PageResult;
import com.rbac.web.model.PageV0;
import com.rbac.web.model.Role;
import com.rbac.web.model.res.RoleGetListRes;
import com.rbac.web.service.IRoleService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.util.List;

/**
 * @author gengaoliu
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(description = "角色列表请求参数")
public class RoleGetListReq extends PageBase {
  @Parameter(description = "角色名称")
  private String name;

  public PageResult<RoleGetListRes> execute(String name, PageV0 pageV0, IRoleService roleService) {
    PageResult<Role> all = roleService.findAll(name, pageV0);
    List<RoleGetListRes> list = all.getList().stream().map(RoleGetListRes::fromDomain).toList();
    return PageResult.of(all.getPage(), all.getSize(), all.getTotal(), list);
  }
}
